﻿{extends file="../home.html"}
{block name="title"}{$head_title}{/block}
{block name="css"}
<link rel="stylesheet" style="text/css" href="__PUBLIC__/Css/front/user_glb.css?version={$version}">
{/block}
{block name="content"}
	<!--主内容-->
  <div class="ed_cont">
	  <form id="register_form" name="register_form" action="" method="post">
		 	<p>
        <label for="mobile">
            <span class="tit">
                手机号
            </span>
            <input type="tel" id="mobile" name="mobile" value="" placeholder="请输入手机号" />
        </label>
      </p> 
			<div class="bind_val_cont">
				<input type="tel" placeholder="输入短信中的验证码" name="register-valNum" id="register-valNum"/>
				<div class="sendBtn">
					<a class="sendValNum" id="code">获取验证码</a>
				</div>
			</div>
			<div class="submit_btn">
				<a href="javascript:void(0);" id="bind_submit" class="submit">{if $mobile}更换手机号{else}绑定{/if}</a>
			</div>
		  <input type="hidden" name="action" value="bind">
	  </form>
	</div>
	<!--提示层-->
  <div id="tan_wrap"><div id="tan"></div></div>
{/block}
{block name="js"}
<script>
var pre_mobile = '{$mobile}';
var type = pre_mobile == '' ? 1 : 2;
{literal}  
	$( function(){
			
			
			var sec = 60;
			var enabled = true;
			function goTimer(){
				enabled = false;
				$("#code").html(sec+"秒后重发");
				$("#code").addClass("sendBtn_grey");
				setTimeout(loop,1000);
			}

			function loop(){
				console.log(sec);
				sec --;
				$("#code").html(sec+"秒后重发");
				$("#code").addClass("sendBtn_grey");

				if(sec > 0){
					setTimeout(loop,1000);
				}else{
					$("#code").html("重新发送");
					$("#code").removeClass("sendBtn_grey");
					sec = 60;
					enabled = true;
				}
			}

			$('#code').click(function(e){
				e.preventDefault();
				if(!enabled){
					return;
				}
				if(!$("input[name=mobile]").val() || !/\d{11}/.test( $("input[name=mobile]").val() ) ){
					var error="请输入正确的手机号码";
					$("#tan").html(error);
					tishi();
					return;
				}
				var thiz = this;
				$.ajax({
					url:"/FrontUser/send_vcode",
					type:"POST",
					data:{
						mobile : $("input[name=mobile]").val(),
						type : type
					},
					timeout:10000,
					success:function(d){
						if(d)
						{
							if(d == 'success'){
								goTimer();
							}
							else
							{
								alert("对不起，请不要多次点击！");
							}
						}
					}
				});
			});
			
			$('#bind_submit').click(function(e){
				e.preventDefault();
				if(this.parentNode.className.indexOf('disable') != -1) return;
				if(!$("input[name=mobile]").val() || !/\d{11}/.test( $("input[name=mobile]").val() ) ){
					var error="请输入正确的手机号码";
					$("#tan").html(error);
					tishi();
					return;
				}

				if(!$("input[name=register-valNum]").val()){
					var error="请输入正确的验证码";
					$("#tan").html(error);
					tishi();
					return;
				}

				if (type == 2)
				{
					confirm('您确定要更换手机号吗？', "$('#register_form').submit();");
				}
				else
				{
					$('#register_form').submit();
				}
			});
		});
</script>   
{/literal}
{/block}
